package com.acwing.partition21;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author `RKC`
 * @date 2022/6/3 9:44
 */
public class AC2013三条线 {

    private static final int N = 50010;
    private static int[][] p = new int[N][2];
    private static Set<Integer> row = new HashSet<>(), col = new HashSet<>();
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) {
            p[i][0] = nextInt();
            p[i][1] = nextInt();
        }
        writer.println(dfs(0, 0));
        writer.flush();
    }

    private static int dfs(int u, int cnt) {
        if (cnt > 3) return 0;
        if (u == n) return 1;
        //如果已经有线能覆盖当前的点，直接尝试下一个点
        if (row.contains(p[u][0]) || col.contains(p[u][1])) return dfs(u + 1, cnt);
        //不能覆盖，分别枚举添加横线和竖线
        row.add(p[u][0]);
        if (dfs(u + 1, cnt + 1) == 1) return 1;
        row.remove(p[u][0]);
        col.add(p[u][1]);
        if (dfs(u + 1, cnt + 1) == 1) return 1;
        col.remove(p[u][1]);
        return 0;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
